<template>
  <div>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-card
        v-for="item in list"
        :key="item.id"
        :title="item.title"
        :thumb="item.img_url"
        @click="godetail(item.id)"
      >
        <span slot="num">点击了{{item.click}}次</span>
        <span slot="price">发表时间：{{item.add_time|formDate}}</span>
      </van-card>
    </van-pull-refresh>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      isLoading: false
    };
  },

  methods: {
    async newLists() {
      var { data: res } = await this.axios.get("/api/getnewslist");
      console.log(res);
      if (res.status !== 0) {
        return this.$toast.fail("服务器异常");
      }
      this.list = res.message;
      console.log(this.list);
    },
    godetail(id) {
      // console.log(id);

      this.$router.replace(`/newsinfo/${id}`);
    },
    onRefresh() {
      setTimeout(() => {
        this.isLoading = false;
      }, 500);
    }
  },

  created() {
    this.newLists();
  }
};
</script>

<style lang='less' scoped>
.van-card__title {
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
  margin: 5px 0;
}
.van-card__price,
.van-card__num {
  font-size: 12px;
  color: #226aff;
}
</style>
